# -*- coding: utf-8 -*-
########################################################################
#   Pax-Selector. Copyright 2010, Hector Sanjuán.                      #
#                                                                      #
#   Pax-selector is free software: you can redistribute it and/or      #
#   modify it under the terms of the GNU General Public License as     #
#   published by the Free Software Foundation, either version 3 of     #
#   the License, or any later version.                                 #
#                                                                      #
#   Pax-selector is distributed in the hope that it will be useful,    #
#   but WITHOUT ANY WARRANTY; without even the implied warranty of     #
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      #
#   GNU General Public License for more details.                       #
#                                                                      #
#   You should have received a copy of the GNU General Public License. #
#   If not, see <http://www.gnu.org/licenses/>.                        #
#                                                                      #
########################################################################

require 'rexml/document'
include REXML

CONFIG="config.xml"

class PaxUtils

  def self.readFields(which='FIELDS')
    
    f = File.new(CONFIG)
    xml_doc = Document.new(f)
    xml_doc.root
    fields=[]
    xml_doc.root.elements[which].each_element() do | field |
      fields << field.text
    end
    f.close
    return fields
  end
  
  def self.users
    f = File.new(CONFIG)
    users = {}
    xml = Document.new(f).root
    xml.elements["USERS"].each_element('USER') do |user|
      username = user.elements["USERNAME"].text
      pw = user.elements["PASSWORD"].text
      users[username] = pw
    end
    f.close
    return users
  end
  
  
  def self.usernames
	users.collect {|name,pw| name}
  end	

end
